package entity;


import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;

/***
 * 聊天信息表，包括好友聊天，话题聊天
 */
public class Chat {

    public static final String TAG = "Chat";

    //好友聊天类型
    public static final int CHAT_TYPE_CONTACT = 0;
    //话题聊天类型
    public static final int CHAT_TYPE_FEED = 1;

    //id，自增长列
    private Long id;

    //头像
    private String iconUri;

    //聊天描述，如果是话题则表示话题名称
    private String caption;

    //聊天类型，话题或好友
    private int type;

    //话题ID
    private long taggedId;

    //聊天内容最后一次简述
    private String abstr;

    private boolean isNew; //是否包含新信息

    //时间
    private long updateTime;


    public Chat(Long id, String iconUri, String caption, int type,
                long taggedId, String abstr, boolean isNew, long updateTime) {
        this.id = id;
        this.iconUri = iconUri;
        this.caption = caption;
        this.type = type;
        this.taggedId = taggedId;
        this.abstr = abstr;
        this.isNew = isNew;
        this.updateTime = updateTime;
    }


    public Chat() {
    }


    public String getUpdateTimeStr() {
        Calendar today = Calendar.getInstance();
        today.set(Calendar.MILLISECOND, 0);
        today.set(Calendar.SECOND, 0);
        today.set(Calendar.MINUTE, 0);
        today.set(Calendar.HOUR, 0);
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(updateTime);

        if (updateTime >= today.getTimeInMillis()) {
            SimpleDateFormat sdf = new SimpleDateFormat("HH:mm", Locale.CHINA);
            return sdf.format(c.getTime());
        }

        today.add(Calendar.DATE, -1);
        if (updateTime >= today.getTimeInMillis()) {
            return "昨天";
        }

        today.add(Calendar.DATE, -2);
        if (updateTime >= today.getTimeInMillis()) {
            switch (c.get(Calendar.DAY_OF_WEEK)) {
                case Calendar.MONDAY:
                    return "周一";
                case Calendar.TUESDAY:
                    return "周二";
                case Calendar.WEDNESDAY:
                    return "周三";
                case Calendar.THURSDAY:
                    return "周四";
                case Calendar.FRIDAY:
                    return "周五";
                case Calendar.SATURDAY:
                    return "周六";
                case Calendar.SUNDAY:
                    return "周日";
            }

        }

        boolean isSameYear = today.get(Calendar.YEAR) == c.get(Calendar.YEAR);
        if (isSameYear) {
            SimpleDateFormat sdf = new SimpleDateFormat("M月d日", Locale.CHINA);
            return sdf.format(c.getTime());
        }

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年M月d日", Locale.CHINA);
        return sdf.format(c.getTime());
    }


    public Long getId() {
        return this.id;
    }


    public void setId(Long id) {
        this.id = id;
    }


    public String getIconUri() {
        return this.iconUri;
    }


    public void setIconUri(String iconUri) {
        this.iconUri = iconUri;
    }


    public String getCaption() {
        return this.caption;
    }


    public void setCaption(String caption) {
        this.caption = caption;
    }


    public int getType() {
        return this.type;
    }


    public void setType(int type) {
        this.type = type;
    }


    public long getTaggedId() {
        return this.taggedId;
    }


    public void setTaggedId(long taggedId) {
        this.taggedId = taggedId;
    }


    public String getAbstr() {
        return this.abstr;
    }


    public void setAbstr(String abstr) {
        this.abstr = abstr;
    }


    public boolean getIsNew() {
        return this.isNew;
    }


    public void setIsNew(boolean isNew) {
        this.isNew = isNew;
    }


    public long getUpdateTime() {
        return this.updateTime;
    }


    public void setUpdateTime(long updateTime) {
        this.updateTime = updateTime;
    }


}
